<?php
namespace App\Common\Cla\Weixin\OfficialAccount;

use App\Common as com;
use App\Common\Cla\Weixin\OfficialAccount as nameOfficialAccount;

class Auth extends nameOfficialAccount\Base\OfConfig {

	/**
	 * @param string $code
	 * @return \Overtrue\Socialite\User
	 * object(Overtrue\Socialite\User)#1447 (2) {
			["provider":protected] => object(Overtrue\Socialite\Providers\WeChat)#1417 (15) {
			["baseUrl":protected] => string(29) "https://api.weixin.qq.com/sns"
			["scopes":protected] => array(1) {
			[0] => string(15) "snsapi_userinfo"
			}
			["withCountryCode":protected] => bool(false)
			["component":protected] => NULL
			["openid":protected] => string(28) "ohU1G6_6pGR0hlHqNUtx48QNz6Dk"
			["state":protected] => NULL
			["config":protected] => object(Overtrue\Socialite\Config)#1418 (1) {
			["config":protected] => array(4) {
			["client_id"] => string(18) "wx3a4e4e39b11e04e4"
			["client_secret"] => string(32) "321017b5e1c93f012de68b7cbf5b41c1"
			["redirect"] => string(9) "http://:/"
			["redirect_url"] => string(9) "http://:/"
			}
			}
			["redirectUrl":protected] => string(9) "http://:/"
			["parameters":protected] => array(0) {
			}
			["scopeSeparator":protected] => string(1) ","
			["httpClient":protected] => uninitialized(GuzzleHttp\Client)
			["guzzleOptions":protected] => array(0) {
			}
			["encodingType":protected] => int(1)
			["expiresInKey":protected] => string(10) "expires_in"
			["accessTokenKey":protected] => string(12) "access_token"
			["refreshTokenKey":protected] => string(13) "refresh_token"
			}
			["attributes":protected] => array(10) {
			["id"] => string(28) "ohU1G6_6pGR0hlHqNUtx48QNz6Dk"
			["name"] => string(7) "Gutink."
			["nickname"] => string(7) "Gutink."
			["avatar"] => string(132) "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKD5aBaq9MCpYalzFaQaCJZ4ia5HWxFrWAmWAlmdryLHbxrZKwX5hKJJia9IibHK65otIYdPibzaIg4Sg/132"
			["email"] => NULL
			["raw"] => array(9) {
			["openid"] => string(28) "ohU1G6_6pGR0hlHqNUtx48QNz6Dk"
			["nickname"] => string(7) "Gutink."
			["sex"] => int(0)
			["language"] => string(0) ""
			["city"] => string(0) ""
			["province"] => string(0) ""
			["country"] => string(0) ""
			["headimgurl"] => string(132) "https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTKD5aBaq9MCpYalzFaQaCJZ4ia5HWxFrWAmWAlmdryLHbxrZKwX5hKJJia9IibHK65otIYdPibzaIg4Sg/132"
			["privilege"] => array(0) {
			}
			}
			["access_token"] => string(110) "72_QGPKG0eWs_RQr5Ec8YTc3rj1V15XOY5sjsqECtpJbt4vD4XLyW2ohV25BIpcjJdYxjGjNbtomSkEVzFPZT5_4WxtVYeh51vgdx3diP1PN14"
			["refresh_token"] => string(110) "72_yWlsgs0QyU2ePVxZ1PqHHlblSxdRZebgd3T74uRoV4B5N4BS_tOJZrMpukumWiqZxwbn5YYMszV8Sz0nTwEU83ZnFqTISosCfewsh6kdg5I"
			["expires_in"] => int(7200)
			["token_response"] => array(5) {
			["access_token"] => string(110) "72_QGPKG0eWs_RQr5Ec8YTc3rj1V15XOY5sjsqECtpJbt4vD4XLyW2ohV25BIpcjJdYxjGjNbtomSkEVzFPZT5_4WxtVYeh51vgdx3diP1PN14"
			["expires_in"] => int(7200)
			["refresh_token"] => string(110) "72_yWlsgs0QyU2ePVxZ1PqHHlblSxdRZebgd3T74uRoV4B5N4BS_tOJZrMpukumWiqZxwbn5YYMszV8Sz0nTwEU83ZnFqTISosCfewsh6kdg5I"
			["openid"] => string(28) "ohU1G6_6pGR0hlHqNUtx48QNz6Dk"
			["scope"] => string(15) "snsapi_userinfo"
			}
			}
			}

	 * @throws
	 */
	public function userFromCode( string $code ):\Overtrue\Socialite\User {
		$res = $this->getEasyObj()->oauth->userFromCode( $code );
		if( isset( $res['errcode'] ) ){
			throw com\Lib\Err\Exception::makeOfNew( '获取失败，code：' . $res['errcode'], com\Lib\Err\Code::$sysAssertError );
		}
		//
		return $res;
	}

}
